#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Kernel Configuration Generator
内核配置生成器

用于生成 kernel_capabilities.json 配置文件
"""

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import

import os
import sys

# 添加模块路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from modules.environment.detector import EnvironmentAnalyzer
from modules.environment.capabilities import KernelCapabilities


def main():
    """主函数"""
    print("="*60)
    print("内核配置生成器")
    print("="*60)
    
    try:
        # 创建环境分析器
        analyzer = EnvironmentAnalyzer()
        
        # 执行完整分析
        print("[*] 开始环境分析...")
        result = analyzer.full_analysis()
        
        # 打印分析摘要
        analyzer.print_analysis_summary()
        
        # 运行详细的能力检查
        print("\n[*] 开始详细能力检查...")
        capabilities = KernelCapabilities()
        runtime_results = capabilities.run_full_capability_check()
        
        # 打印能力摘要
        capabilities.print_capability_summary()
        
        # 生成最终报告
        report = capabilities.generate_capability_report()
        
        print("\n[+] 配置生成完成!")
        print(f"[+] 配置文件路径: {result.get('config_path', 'Unknown')}")
        print(f"[+] 检测到 {report['summary']['available_features']} 项可用特性")
        
        return True
        
    except Exception as e:
        print(f"[!] 配置生成失败: {e}")
        import traceback
        traceback.print_exc()
        return False


if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)